package com.esm.tool;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.esm.app.MyApplication;
import com.esm.netity.BadlyTongji;
import com.esm.view.R;
import com.esm.view.R.color;
import com.esm.view.SecondActivity;

import java.util.List;

public class MylisAdapter extends BaseAdapter {
    private final boolean isupDate = false;
    private SecondActivity mContext = null;
    private List<BadlyTongji> mData;
    private ViewHolder holder;
    private boolean isadd;
    private boolean isOrderZero;

    public MylisAdapter(SecondActivity lushuUtils, List<BadlyTongji> data) {
        mContext = lushuUtils;
        mData = data;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    public void setData(List<BadlyTongji> mData) {
        this.mData = mData;
    }


    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gv1, parent, false);
            holder = new ViewHolder();
            holder.id = (TextView) convertView.findViewById(R.id.gv_id);
            holder.tv_code = (TextView) convertView.findViewById(R.id.gv_code);
            holder.tv_num = (TextView) convertView.findViewById(R.id.gv_num);
            holder.ll = (LinearLayout) convertView.findViewById(R.id.gv_ll);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (mData.get(position).getZt().equals("1"))
            holder.ll.setBackgroundColor(color.A1A1A1);
        else {
            holder.ll.setBackgroundColor(Color.parseColor("#b6d8f3"));
        }
        holder.id.setText(position + 1 + "");
        String code = mData.get(position).getCode();
        String name = Utils.getLeixing(mContext, MyApplication.yy, code);
        holder.tv_code.setText(name);

        String num = mData.get(position).getNum();
        String name2 = Utils.getLeixing(mContext, MyApplication.yy, num);
        holder.tv_num.setText(name2);
        return convertView;

    }

    static final class ViewHolder {
        TextView id, tv_code, tv_num;
        LinearLayout ll;
    }

}
